package plugins

import (
	. "go-caipu/pkg/services/sqlstore/migrator"
)

func AddPluginDataSourceMigrations(mg *Migrator) {
	datasourceV1 := Table{
		Name: "sys_plugin_datasource",
		Columns: []*Column{
			{Name: "id", Type: DB_BigInt, IsPrimaryKey: true, IsAutoIncrement: true},
			{Name: "version", Type: DB_BigInt, Length: 4, Nullable: true},
			{Name: "type", Type: DB_NVarchar, Length: 100, Nullable: false},
			{Name: "name", Type: DB_NVarchar, Length: 255, Nullable: false},
			{Name: "access", Type: DB_NVarchar, Length: 255, Nullable: true},
			{Name: "url", Type: DB_NVarchar, Length: 100, Nullable: true},
			{Name: "is_default", Type: DB_Int, Length: 4, Nullable: true},
			{Name: "json_data", Type: DB_NVarchar, Length: 600, Nullable: true},
			{Name: "secure_json_data", Type: DB_NVarchar, Length: 600, Nullable: true},
			{Name: "read_only", Type: DB_NVarchar, Length: 64, Nullable: true},
			{Name: "create_by", Type: DB_BigInt, Nullable: false},
			{Name: "update_by", Type: DB_BigInt, Nullable: true},
			{Name: "created_at", Type: DB_DateTime, Nullable: false},
			{Name: "updated_at", Type: DB_DateTime, Nullable: true},
		},
		Indices: []*Index{
			{Cols: []string{"name"}, Type: UniqueIndex},
		},
	}
	//create table
	mg.AddMigration("create table sys_plugin_datasource", NewAddTableMigration(datasourceV1))
}
